package com.example.photography.fragment.group;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.adapter.group.GroupHotAdapter;
import com.example.photography.bean.Group_ProductBean;
import com.example.photography.bean.Home_RecommendBean;
import com.example.photography.common.BaseFragment;
import com.example.photography.util.Util;
import com.example.photography.view.MyListView;
import com.loopj.android.http.RequestParams;

import java.util.List;

import butterknife.BindView;

public class Group_Hot extends BaseFragment {
    @BindView(R.id.lv_item)
    MyListView lvItem;
    private List<Group_ProductBean> group_productBeans;
    private GroupHotAdapter groupHotAdapter;


    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return null;
    }

    @Override
    protected void initData(String content) {
        content = Util.getJson(getContext(), "group_hot.json");
        if (TextUtils.isEmpty(content)) {//数据为空
            return;
        }
        JSONObject jsonObject = JSON.parseObject(content);
        int status = jsonObject.getInteger("code");
        if (status == 202) {
            String data = jsonObject.getString("data");
            //封装转json数据
            group_productBeans = JSONObject.parseArray(JSON.parseObject(data).getString("product_list"), Group_ProductBean.class);
            initView();
        } else {
            // TODO: 2021/5/2 加没数据的判断
        }
    }

    private void initView() {
        groupHotAdapter = new GroupHotAdapter(group_productBeans,getContext());
        lvItem.setAdapter(groupHotAdapter);
    }

    @Override
    public int getLayoutId() {
        return R.layout.lv_listview;
    }
}
